import { defineStore } from 'pinia'
import { ref } from "vue";

// 组合式 
export const useUserStore = defineStore('user', () => {
  const profile = ref('')
  const selectedAddress = ref({})
  const setProfile = (data) => {
    profile.value = data
  }
  const address = (userItem) => {
    selectedAddress.value=userItem
  }

  const removeItem = () => {
    profile.value=[]
  }

 
  return {
    profile, setProfile, address,removeItem
  }
}, {
  // 只在浏览器端下有效  小程序端无效
  // persist: true 

  // uniapp 重写存储数据的api
  persist: {
    // storage:localStorage,
    storage: {
      getItem(key) {
        return uni.getStorageSync(key)
      },
      setItem(key, val) {
        uni.setStorageSync(key, val)
      },
    
    }
  }

})
